package wxwoa

import (
	"encoding/gob"

	"github.com/kataras/iris/v12"
	"github.com/kataras/iris/v12/mvc"
)

// RegisteRouters 注册路由
func RegisteRouters(app *iris.Application) {
	// 当使用 utils.SetCache 一个结构体实例时，必须要先注册
	gob.Register(&WxConfig{})

	wx := mvc.New(app.Party("/wx"))
	// wx.Router.SetExecutionRules(iris.ExecutionRules{
	// 	// Begin:  <- from `Use[all]` to `Handle[last]` future route handlers, execute all, execute all even if `ctx.Next()` is missing.
	// 	// Main:   <- all `Handle` future route handlers, execute all >> >>.
	// 	Done: iris.ExecutionOptions{Force: true}, // <- from `Handle[last]` to `Done[all]` future route handlers, execute all >> >>.
	// })
	// wx.Router.Done(doneHandler)

	wx.Handle(new(WxTokenCheckController))
	wx.Handle(new(WxAuthorizeController))
	wx.Handle(new(WxIndexController))
	wx.Handle(new(WxMenuController))
	wx.Handle(new(WxLocationController))
	wx.Handle(new(WxShareController))
	wx.Handle(new(WxTemplateMessageController))

	app.PartyFunc("/wx", func(wxapi iris.Party) {
		wxapi.Any("/test", index)
	})

}

func doneHandler(ctx iris.Context) {
	ctx.WriteString("\nFrom Done Handler")
}

func index(ctx iris.Context) {
	ctx.HTML("<h1 style='color:green;'>恭喜您，接口网络通畅</h1>")
	ctx.HTML("<p>appid:" + WeChatSubscriptionAppID(ctx) + "</p>")
}
